package com.appspot.bs24event.controller.event.attendance;

import java.util.List;

import org.apache.log4j.Logger;
import org.slim3.controller.BaseController;
import org.slim3.controller.Navigation;

import com.appspot.bs24event.controller.event.ListController;
import com.appspot.bs24event.model.Attendance;
import com.appspot.bs24event.service.AttendanceService;
import com.google.appengine.api.datastore.Key;

public class DetailController extends BaseController {
    public final static String SHUSSEKI ="○";
    public final static String KESSEKI ="×";
    public final static String MITEI ="△";

    /** ログ */
    protected static final Logger logger = Logger.getLogger(ListController.class.getName());

    private AttendanceService service = new AttendanceService();

    @Override
    protected Navigation setUp() {
        logger.info(this.getClass().getName() + " start.");
        return super.setUp();
    }

    @Override
    protected void tearDown() {
        logger.info(this.getClass().getName() + " end.");
        super.tearDown();
    }

    @Override
    public Navigation run() throws Exception {

        return doGet();
    }

    private Navigation doGet() {

        Key eventKey = asKey("key");
        Long eventVersion = asLong("version");
        List<Attendance> list = service.getList(eventKey, eventVersion);
        int intShusseki = service.getCount(eventKey, eventVersion, SHUSSEKI);
        int intKesseki = service.getCount(eventKey, eventVersion, KESSEKI);
        int intMitei =  service.getCount(eventKey, eventVersion, MITEI);
        requestScope("attendanceList", list);
        requestScope("key", request.getParameter("key"));
        requestScope("version", request.getParameter("version"));
        requestScope("Shusseki",intShusseki);
        requestScope("Kesseki",intKesseki);
        requestScope("Mitei",intMitei);

        return forward("attendance.jsp");

    }

}